package com.ztools.pc.controller.information;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.information.Teacher;
import com.ztools.common.model.pc.information.TeacherClasses;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.information.TeacherClassesService;
import com.ztools.pc.service.information.TeacherService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author:一口香菜
 * @Date: 2023/3/13  14:23
 * @Version 1.0
 */
@RestController
@RequestMapping("/information/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;
    @Resource
    private TeacherClassesService teacherClassesService;

    @RequestMapping("/list")
    public Result findList(@RequestBody PageUtil<Teacher> pageUtil) {
        Page<Teacher> list = teacherService.findList(pageUtil);
        return list != null ? Result.success().data(list) : Result.error();
    }

    @RequestMapping("findByObject")
    public Result findByObject(@RequestBody Teacher teacher) {
        List<Teacher> list = teacherService.findByObject(teacher);
        return list != null ? Result.success().data(list) : Result.error();
    }

    @GetMapping("/findListByClassesId")
    public Result findListByClassesId(Long classesId) {
        List<Teacher> list = teacherService.findListByClassesId(classesId);
        return Result.success().data(list);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Teacher teacher) {
        boolean b = teacherService.update(teacher);
        return b ? Result.success("修改成功") : Result.error("修改失败");
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody Teacher teacher) {
        boolean b = teacherService.delete(teacher);
        return b ? Result.success("删除成功") : Result.error("删除失败");
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Teacher teacher) {
        boolean b = teacherService.add(teacher);
        return b ? Result.success("添加成功") : Result.error("添加失败");
    }

    @RequestMapping("/delete/teacher/classes")
    public Result deleteTeacherClasses(@RequestBody TeacherClasses teacherClasses) {
        boolean b = teacherClassesService.deleteTeacherClasses(teacherClasses);
        return b ? Result.success("删除成功") : Result.error("删除失败");
    }

    @RequestMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody Teacher teacher) {
        teacherService.exportExcel(response, teacher);
    }

}
